exports.popup = function(_args){
	var pathimage=Ti.App.Properties.getString('pathimage');
	var platformWidth=Titanium.Platform.displayCaps.platformWidth;//Ti.App.Properties.getInt('platformWidth');
	var platformHeight=Titanium.Platform.displayCaps.platformHeight;//Ti.App.Properties.getInt('platformHeight');
    var win = Ti.UI.createWindow({
        backgroundColor: 'gray',
        fullscreen: true,
        navBarHidden:true,
        opacity : 0.50,
        id : "popup",
        orientationModes:[
	        Titanium.UI.LANDSCAPE_LEFT,
	        Titanium.UI.LANDSCAPE_RIGHT,
		],
		id: 'ChangeTablePopup',
    });

 
    var blur = Ti.UI.createAnimation({
        opacity: 0.50
    })
    var shadow = Ti.UI.createView({
        left: 10,
        top: 10,
        right: 10,
        bottom: 10,
        opacity: 0.50,
        backgroundColor: 'black',
        borderRadius: 10,
        borderColor: 'black'
    });
    var win_view = Ti.UI.createView({
        top : 20,
        left: 20,
        right: 20,
        bottom: 20,
        opacity: 1,
        borderRadius: 10,
        backgroundColor: 'white',
        width:platformWidth-40
      //  layout: "vertical"
    });
 
    Ti.include('cs/EventGarbageCollection.js')
    var egc = new globals.EventGarbageCollection(win);
    egc.addEventListener('back_'+win.id, function () {
    	Lhs.navGroup.close(win, {
             animated: true
        });
    	
	});
	
	var header = Ti.UI.createView({
	    top: 0,
	    height:30,
	    width:platformWidth,
	    backgroundColor: '#ffffe0',
	});
	win_view.add(header);
	var lb1 = Ti.UI.createLabel({
	  	text:'Chọn bàn mà bạn muốn chuyển',
	  	color:'black',
	  	font:{
				fontSize:17,//Ti.App.Properties.getInt('fontsize_header'),
				fontWeight:'bold',
		},
	});
	header.add(lb1);
	
	var LoadLocationControl = function(data) {
		
 		//////////////LOCATION///////////////
		var location=require('controls/ChangeTable_location').Createlocation({
				top:header.height,
				idWinParent:win.id,
		 		width:Ti.App.Properties.getInt('TableWindow_LocationWidth'),
		 		height:platformHeight-header.height,
			    data:data,
			    parent:win
	    })
	    win_view.add(location)
    }
	
	
	
	//TABLE VIEW
    var tb_Table=Ti.UI.createTableView({
		  	backgroundColor:'Transparent',
		  	separatorColor:'Transparent',
		  	top:header.height,
		  	height:platformHeight-header.height,
		  	width:win_view.width-150,//platformWidth-150,
		  	left:0,
		  	right:0,
		  	bottom:0,
    })
	tb_Table.addEventListener('click', function (e) {
    	
    	
	});
	win_view.add(tb_Table);
	
	
	
	
    //////////////LIST TABLE///////////////
    var row_in=Ti.App.Properties.getInt('Table_row_in');
    var col_in=Ti.App.Properties.getInt('Table_col_in');
    var LoadTablesDemo_Data = function(TableScreen_Id) {
 		var json=require('db').selectTableScreenTables(TableScreen_Id);
		return json;
    }
  
    var width_bt=tb_Table.width/col_in;
    var height_bt=tb_Table.height/row_in;
    var createButton = function (bt,left) {
		
		var backgroundImage,backgroundSelectedImage
		Ti.API.info('Ticket:'+bt.TicketId)
		if(bt.TicketId==0)
		{
			 backgroundImage=pathimage+'tb1.png'
			 backgroundSelectedImage=pathimage+'bt_Green.png'
		}
		else
		{
			Ti.API.info('IsTicketLocked:'+bt.IsTicketLocked)
			if(bt.IsTicketLocked==0)
			{
				 backgroundImage=pathimage+'bt_Green.png'
				 backgroundSelectedImage=pathimage+'bt_Green.png'
			}
			else
			{
				 backgroundImage=pathimage+'bt_red.png'
				 backgroundSelectedImage=pathimage+'bt_Green.png'
			}
		}
		var bta = Titanium.UI.createButton({
			
		     borderColor: Ti.App.Properties.getString('borderColor'),
		     borderRadius: Ti.App.Properties.getInt('borderRadius'),
		     borderWidth:Ti.App.Properties.getInt('borderWidth'),
			 color:'Black',
			 Table_Id:bt.Table_Id,
			 TableScreen_Id:bt.TableScreen_Id,
			 TicketId:bt.TicketId,
			 title:bt.Name,
			 backgroundImage:backgroundImage,
			 backgroundSelectedImage:backgroundSelectedImage,
			 width:width_bt,
		 	 height:height_bt,
		   	 left:left,
		   	 font:{
				fontSize:Ti.App.Properties.getInt('MainWindow_btnumber_fontsize'),
				fontWeight:'bold',
		 	 },
		   	 	 
		}); 
		bta.addEventListener('click', function (e) {
			
	   })
	   return bta;
	}
	
    var CreateTableViewRow = function(e) {
		var item=e.data;
		var row = Ti.UI.createTableViewRow({
	            height:tb_Table.height/row_in,
		})
		var left_bt=0;
		for (var c=0;c<item.length;c++){
			
			if(item[c]!=undefined)
			{
				var bt=createButton(item[c],left_bt)
				row.add(bt);
				left_bt+=width_bt;
			}
			
		}
		return row;
	};
    var LoadTables = function(TableScreen_Id) {
    	
 		var tableData=[];
 		var json=[];
 		
 		if (Ti.App.Properties.getInt('IsDemo')==1) 
 		{
 			json=LoadTablesDemo_Data(TableScreen_Id);
 		}
 		else
 		{
 			
 		}
 		
 		
 		require('settings').LoadedData2TableView(tb_Table,json,CreateTableViewRow,col_in);
	};
	//////////////LOCATION///////////////
	var LoadLocationDemo_Data = function() {
 		var json=require('db').selectTableScreens();
		return json;
    }
    var LoadLocation = function(e) {
    	
 		var tableData=[];
 		var json=[];
 		
 		if (Ti.App.Properties.getInt('IsDemo')==1) 
 		{
 			json=LoadLocationDemo_Data();
 		}
 		else
 		{
 			
 		}
 		LoadLocationControl(json);
	};
	/////////////EVEN/////////////////////////
	win.addEventListener('open', function (e) {
		LoadLocation()
		LoadTables(1)
	});
	
	egc.addEventListener('ChangeTablePopup:locationSelect', function (e) {
		LoadTables(e.data)
	})
	
    //frmLog.add(btnLog);
    
    shadow.animate(blur);
    win.add(shadow);
    win.add(win_view);
    return win;
}